package com.zyong.design.pattern.strategy.case3;

/**
 * @program: zyong-design-pattern
 * @ClassName: Duck
 * @author: zyong
 * @create: 2024-04-14 13:06
 */
public abstract class Duck {
    protected FlyBehavior flyBehavior;
    protected QuackBehavior quackBehavior;
    protected SwimBehavior swimBehavior;

    public void setFlyBehavior(FlyBehavior flyBehavior) {
        this.flyBehavior = flyBehavior;
    }

    public void setQuackBehavior(QuackBehavior quackBehavior) {
        this.quackBehavior = quackBehavior;
    }

    public void setSwimBehavior(SwimBehavior swimBehavior) {
        this.swimBehavior = swimBehavior;
    }

    protected void fly() {
        if (flyBehavior != null) {
            flyBehavior.fly();
        }
    }

    protected void quack() {
        if (quackBehavior != null) {
            quackBehavior.quack();
        }
    }

    protected void swim() {
        if (swimBehavior != null) {
            swimBehavior.swim();
        }
    }

    protected abstract void display();
}
